package com.googlecode.aleverr.yafotkiclient.api;

import android.content.Context;
import android.content.SharedPreferences;

public class GlobalSettings {

    private static final String PREFERENCES_NAME = "YaFotkiClient";

    private static GlobalSettings instance;

    public static GlobalSettings getInstance(Context context) {
        if (instance == null) {
            instance = new GlobalSettings(context);
        }
        return instance;
    }

    private final SharedPreferences settings;
    private String accessToken;
    private UserHome userHome;

    private GlobalSettings(Context context) {
        settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
        accessToken = settings.getString("accessToken", "");
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("accessToken", accessToken);
        editor.commit();
    }

    public UserHome getUserHome() {
        return userHome;
    }

    public void setUserHome(UserHome userHome) {
        if (userHome != null) {
            this.userHome = userHome;
        }
    }
}
